package cn.wzx.respJson;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

// 获取到登录后的token，从中获取到登录者的信息，从而获取到用户ID
public class Token {
    public static Object getUser(){
        Object principal =
                SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println("principal=" + principal);
        if (principal==null) return null;
        if (principal instanceof UserDetails){
            return (UserDetails) principal;
        }
        return null;
    }
}
